$(function() {
	//初始化
	begin();
})

var sendMessL = new Vue({
	el: "#sendMessage",
	data: function() {
		return {
			ruleForm: {
				// 用于上传图片
				photo: "",
			},
			// 用于展示，图片的保存路径
			photoUrl: "/templates/img/default.jpg"
		};
	},
	methods: {
		beforeAvatarUpload: function(file) {
			var isJPG = file.type === 'image/jpeg';
			var isLt2M = file.size / 1024 / 1024 < 2;

			if(!isJPG) {
				this.$message.error('上传头像图片只能是 JPG 格式!');
			}
			if(!isLt2M) {
				this.$message.error('上传头像图片大小不能超过 2MB!');
			}
			return isJPG && isLt2M;
		},
		//点击图片裁剪事件
		handleChange: function(file, fileList) {
			userAvaterCropper.dialogVisible = true;
			userAvaterCropper.imgSrc = file.url;
			setTimeout(function() {
				userAvaterCropper.initCropper("avater_be_cropper");
			}, 500);
		}
	}
})

//初始化
function begin() {
	//面包屑
	new Vue().$mount('#crumbs');
	//发消息
	//	new Vue().$mount('#sendMessage');
	sessionStorage.Jurisdiction = "base_tag_addBaseRootTag,base_team_delTeamUsesr,base_user_update,base_tag_modifyBaseTag,base_team_modify,base_role_modifyRFAAndRemove,base_tagUser_export,base_customerUser_export,base_role_modifyRoleInfo,base_customer_import,base_org_delete,base_customer_addTag,base_team_delete,base_org_export,base_role_modifyRoleUser,base_user_resetUserStatus,base_org_import,base_user_export,base_tag_modifyTag,base_customer_add,base_customer_modifyTag,base_user_resetUserPassword,base_user_import,base_team_addTeamUsers,base_tag_deleteTag,base_user_deleteUsers,base_org_update,base_role_deleteRoleUser,base_user_moveUsers,base_teamUser_export,base_tag_addBaseTag,base_team_add,base_tag_selectTagUser,base_tag_addTag,base_customer_delCustomer,base_customer_addRootTag,base_tag_addRootTag,base_org_add,base_user_updateOrderNum,base_tag_deleteTagUser,base_tag_deleteBaseTag,base_customer_deleteTag,base_org_updateOrderNum,base_user_add"
}

/*图片裁剪器*/
var userAvaterCropper = new Vue({
	el: "#userindexUserCropper",
	data: function() {
		return {
			dialogVisible: false,
			imgSrc: "",
			cropper: ""
		}
	},
	methods: {
		updateAvater: function(isUpated) {
			if(isUpated) {
				var canvas = this.cropper.getCroppedCanvas({
					width: 320,
					height: 320
				});
				//定义位置对图像赋值
				sendMessL.ruleForm.photo = canvas.toDataURL('image/jpeg');
				sendMessL.photoUrl = canvas.toDataURL('image/jpeg');
			}
			this.imgSrc = "";
			this.cropper.destroy();
			this.dialogVisible = false;
		},
		initCropper: function(imgEl) {
			var image_ = document.getElementById(imgEl);
			this.cropper = new Cropper(image_, {
				viewMode: 1,
				aspectRatio: 1 / 1
			});
		}
	}
});